package studentsinfomanagement.view.administrator;

import studentsinfomanagement.bean.Administrator;
import studentsinfomanagement.dao.AdministratorDAO;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 管理员主页类

 */
public class AdministratorHomeView extends JFrame {

    private AdministratorHomeView administratorHomeView = null;
    private Administrator administrator = null;

    public AdministratorHomeView(Administrator administrator){
        administratorHomeView = this;
        this.administrator = administrator;

        initAdministrator();

        this.setTitle("管理员界面");//标题
        this.setSize(350,400);//大小
        this.setLocationRelativeTo(null);//居中
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭界面退出程序
        this.setResizable(false);//大小不可调节

        GridLayout gl = new GridLayout();//网格布局
        gl.setRows(5);
        gl.setColumns(1);
        this.setLayout(gl);

        //界面元素
        JLabel jl_title = new JLabel("管理员主页");//标题
        jl_title.setFont(new Font("Dialog",1,15));//设置字体

        JButton btn_edit = new JButton("修改密码");//修改个人信息按钮
        btn_edit.setPreferredSize(new Dimension(150,25));
        JButton btn_student = new JButton("管理学生信息");//进入学生信息中心
        btn_student.setPreferredSize(new Dimension(150,25));
        JButton btn_teacher = new JButton("管理教师信息");//进入教师信息中心
        btn_teacher.setPreferredSize(new Dimension(150,25));
        JButton btn_course = new JButton("管理课程信息");//进入课程信息中心
        btn_course.setPreferredSize(new Dimension(150,25));


        //标题区域
        JPanel jp_title = new JPanel();
        jp_title.add(jl_title);
        this.add(jp_title);

        //按钮区域
        JPanel jp_edit = new JPanel();
        jp_edit.add(btn_edit);
        this.add(jp_edit);

        JPanel jp_student = new JPanel();
        jp_student.add(btn_student);
        this.add(jp_student);

        JPanel jp_teacher= new JPanel();
        jp_teacher.add(btn_teacher);
        this.add(jp_teacher);

        JPanel jp_course= new JPanel();
        jp_course.add(btn_course);
        this.add(jp_course);

        //设置界面可见
        this.setVisible(true);

        //添加监听器
        //修改密码
        btn_edit.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //显示修改管理员信息界面
                new AdministratorEditView(AdministratorHomeView.this.administrator);
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        //管理学生
        btn_student.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                new AdministratorStudentCenter();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        //管理老师
        btn_teacher.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                new AdministratorTeacherCenter();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        //管理课程
        btn_course.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                new AdministratorCourseCenter();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
    }

    /**
     * 初始化管理员信息
     */
    public void initAdministrator(){
        AdministratorDAO administratorDAO = AdministratorDAO.getInstance();
        administrator = administratorDAO.getAdministratorByAccNum(administrator.getAccNum());
    }

}
